package com.zmn.oms.services.impl.orderattachment;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.orderattachment.OrderAttachment;
import com.zmn.oms.persistence.interfaces.orderattachment.OrderAttachmentDao;
import com.zmn.oms.services.interfaces.orderattachment.OrderAttachmentService;
import io.shardingsphere.api.HintManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 附件信息
 * @author: SongWeidong
 * @create: 2020-10-30
 **/
@Service
public class OrderAttachmentServiceImpl implements OrderAttachmentService {

    @Resource
    OrderAttachmentDao orderAttachmentDao;

    @Override
    public OrderAttachment findAttachmentByKey(Long attachmentId) {
        return orderAttachmentDao.findAttachmentByKey(attachmentId);
    }

    @Override
    public Integer countByOrderIdAndType(Long orderId, Integer type) {
        return orderAttachmentDao.countByOrderIdAndType(orderId, type);
    }

    @Override
    public List<OrderAttachment> listByOrderIdAndType(Long orderId, Integer type) {
        return orderAttachmentDao.listByOrderIdAndType(orderId,type);
    }

    @Override
    public List<OrderAttachment> listAttachmentByOrderId(Long orderId) {
        return orderAttachmentDao.listAttachmentByOrderId(orderId);
    }

    @Override
    public List<OrderAttachment> listAttachmentByOrderIdList(List<Long> orderIdList) {
        return orderAttachmentDao.listAttachmentByOrderIdList(orderIdList);
    }

    @Override
    public List<OrderAttachment> listAttachmentByOrderIdSrcMaster(Long orderId) {
        try (HintManager hintManager = HintManager.getInstance()) {
            hintManager.setMasterRouteOnly();
            return orderAttachmentDao.listAttachmentByOrderId(orderId);
        }
    }

    @Override
    public void insertAttachment(OrderAttachment orderAttachment) {
        orderAttachmentDao.insertAttachment(orderAttachment);
    }

    @Override
    public void insertAttachmentList(List<OrderAttachment> attachmentList) {
        orderAttachmentDao.insertAttachmentList(attachmentList);
    }

    @Override
    public void updateAttachmentSrcByKey(OrderAttachment attachment) {
        orderAttachmentDao.updateAttachmentSrcByKey(attachment);
    }

    @Override
    public void updateBatch(List<OrderAttachment> attachmentList) {
        orderAttachmentDao.updateBatch(attachmentList);
    }

    @Override
    public void updateByKey(OrderAttachment attachment){
        attachment.setUpdateTime(DateUtil.getNow());
        orderAttachmentDao.updateByKey(attachment);
    }

    @Override
    public void deleteByOrderId(Long orderId) {
        orderAttachmentDao.deleteByOrderId(orderId);
    }

    @Override
    public void deleteByKey(Long attachmentId) {
        orderAttachmentDao.deleteByKey(attachmentId);
    }

    @Override
    public void deleteBatchByAttachmentIds(List<Long> attachmentIds) {
        orderAttachmentDao.deleteBatchByAttachmentIds(attachmentIds);
    }


}
